package com.example.demo.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.demo.dto.OrderQueryDTO;
import com.example.demo.service.OrdersService;
import com.example.demo.vo.OrderListVO;
import com.example.demo.vo.OrdersDevVO;
import com.example.demo.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sjy
 * @since 2025-05-25
 */
@RestController
@RequestMapping("/orders")
@Api(tags = "订单管理")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    @PostMapping("/addOrder")
    @ApiOperation("新增订单")
    public ResultVO<String> addOrder(Integer boardroomId, Integer customerId, String bookingDate, String startTime, String endTime, Integer numPeople, Integer state, Double totalPrice) throws Exception{
        return ordersService.addOrder(boardroomId, customerId, bookingDate, startTime, endTime, numPeople, state, totalPrice);
    }

    @PostMapping("/modifyOrder")
    @ApiOperation("稍后支付时支付")
    public ResultVO<String> modifyOrder(Integer orderId, Integer customerId){
        return ordersService.modifyOrder(orderId, customerId);
    }

    @GetMapping("/queryByCustomerId")
    @ApiOperation("根据客户ID查询订单信息")
    public ResultVO<IPage<OrdersDevVO>> queryOrdersByCustomerId(Integer customerId, Integer page, Integer pageSize) {
        IPage<OrdersDevVO> result = ordersService.queryOrdersByCustomerId(customerId, page, pageSize);
        return ResultVO.success("查询成功", result);
    }

    @PostMapping("/applyCancelOrder")
    @ApiOperation("客户申请退订")
    public ResultVO<Double> applyCancelOrder(Integer orderId) {
        return ordersService.applyCancelOrder(orderId);
    }


    @GetMapping("/list")
    @ApiOperation("员工获取订单列表")
    public ResultVO<IPage<OrderListVO>> getOrderList(OrderQueryDTO queryDTO) {
        IPage<OrderListVO> result = ordersService.queryOrdersByCondition(queryDTO);
        return ResultVO.success("查询成功",result);
    }

    @PostMapping("/approve/{id}")
    @ApiOperation("审核通过订单")
    public ResultVO approveOrder(@PathVariable("id") Integer id) {
        return ordersService.approveOrder(id);
    }

    @PostMapping("/reject/{id}")
    public ResultVO rejectOrder(@PathVariable("id") Integer id){
        return ordersService.rejectOrder(id);
    }

}
